home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / toadso11.zip / TOADSO11.ASM < prev    next >
Assembly Source File  |  1986-01-15  |  27KB  |  1,011 lines

  1.     Page    82,132
  2.     Title    TOADSOFT - Convert text file to or from WordStar format
  3.  
  4.     Comment | Version 1.1, 15 Jan 86
  5.  
  6. TOADSOFT Command
  7. -----------------
  8.  
  9. Purpose:   1. Convert text file to WordStar .DOC format
  10.         or convert WordStar .DOC formatted file to text file.
  11.        2.  Replace blanks with tab character(s)
  12.         or expand tabs.
  13.  
  14. Format:    TOADSOFT [d:[input.ext]] [d:[output.ext]] [/t] [/u]
  15.  
  16. Remarks:   Any tab characters found are first expanded. If TABS
  17.     appear within quoted strings - out of context - they will
  18.     not be expanded.
  19.  
  20.     The default is to expand tabs (the normal WordStar DOC format).
  21.     - Carriage return/line feeds within a paragraph are "softened"
  22.       (Cr becomes 13 + 128) to permit WordStar reformatting.
  23.     - If 2 or more spaces in a row, the last space is "softened"
  24.       (Space becomes 32 + 128) to permit WordStar reformatting.
  25.  
  26.     The /U option may be used to Unsoften a WordStar DOC file.
  27.     Tabs (if any) will automatically be expanded unless the
  28.     /T option is selected.
  29.  
  30.     The /T option may be used to replace spaces with tabs, and may
  31.     be used without Unsoftening a W* DOC file.
  32.  
  33.     Both /T and /U may be used together.
  34.  
  35.     Side Effects:  If a normal text file is Unsoftened and tabs
  36.     expanded ('/TU'), non-space characters may be followed by up
  37.     to 3 new spaces (where there used to be a nice neat tab).
  38.     This is an artifact of the minispace .. NO tab will be inserted
  39.     until 3 or more spaces have been used.  Sorry 'bout that.
  40.  
  41.     The maximum logical record size is 255, see MAXREC equate.
  42.     Defacto tab columns are 9,17,25,...
  43.  
  44.     Credits:
  45.     - Majority of file handling and tab processing from
  46.       Vernon Buerg's TABS version 1.6gg, 10 Jul 85.
  47.     - Ensoft procedure from ENSOFT2.C (yep, translated back from C)
  48.       by Gordon Brandley (original author)
  49.       totally rewritten by Harvey G. Lord.
  50.  
  51.     Should run on any MS-DOS system with DOS 2.0 or higher.
  52.     For public domain use.
  53.  
  54.     Author: David Kirschbaum, Toad Hall
  55.         7573 Jennings Lane
  56.         Fayetteville NC  28303
  57.         (919) 868-3471
  58.         ARPAnet ABN.ISCAMS@USC-ISID
  59.  
  60. Notes:
  61.   I do some baaaad things in here .. like not always entering and
  62. leaving procedures at the same place, or beginning and end (tch tch).
  63. But .. I wanted it tight and fast .. and I wrote it for ME to
  64. understand, not necessarily for you.  It always traces logically ..
  65. you'll just have to work at it.
  66. Toad Hall
  67.  
  68. v1.1, 15 Jan 86:  ENSOFT2.C specifies a leading space will turn off the
  69. soft carriage return function for that line.  I don't like that because
  70. it makes reformatting columnar or indented material much harder (all the
  71. hard cr/lfs are still there).  Commented that test out.
  72. Tried softening trailing hyphens (when ensoftening), but too much hassle.
  73. Still one wee little bug .. can't seem to terminate the target file with
  74. a clean Cr/Lf and Ctrl-Z .. always get a couple of spaces or tabs stuffed
  75. in there.  Strange.
  76. [Toad Hall]
  77. -----------------            |
  78.  
  79. CSeg    Segment Public Para 'CODE'
  80.     Assume  CS:Cseg,DS:Cseg,ES:CSeg
  81.     Org    100h
  82.  
  83. Tabs    Proc    Far
  84.     Push    DS            ;DOS convention
  85.     Sub    AX,AX
  86.     Push    AX
  87.  
  88.     Mov    CS:Stk_Top,SP        ;Save stack ptr to insure return
  89.  
  90.     Call    ChkVer            ;Check for DOS 2
  91.  
  92.     Call    Alloc            ;Get maximum I/O buffers
  93.  
  94.     Call    GetFile            ;Get file names
  95.  
  96.     Call    OpenIn            ;Open input
  97.  
  98.     Call    OpenOut            ; and output
  99.  
  100.     Call    Inform            ;Display "cooking" message
  101.  
  102.     Call    GenTab            ;Generate tabs
  103.  
  104.     Call    Flush            ;Empty the output buffer
  105.     mov    BX,Tabcnt        ;get final tab count
  106.     call    Print_count        ;one last time
  107.  
  108.     Mov    DX,Offset EofMsg    ;Say END-OF-FILE
  109. Error:  Mov    SP,Stk_Top        ;Insure proper return
  110.     Call    PrintS            ;Print any message
  111.  
  112.     Call    Close            ;Close files
  113.  
  114.     Ret                ;Return to DOS
  115.     Page
  116.  
  117. Buflen  Dw    0            ;I/O buffer size
  118. MinCore Dw    512            ;Minimum of one sector
  119. Maxrec  Equ    255            ;Longest logical record
  120.  
  121. S_Quote Equ    34            ;Single quote
  122. D_Quote Equ    39            ;Double quote
  123. Tab    Equ    9
  124. Lf    Equ    10
  125. Cr    Equ    13
  126. EOF    Equ    1AH
  127. FormF    Equ    0CH
  128. Soft_Cr  Equ    8DH            ;W* soft carriage return
  129. End_Hyph Equ    1FH            ;W* soft hyphen at end of line
  130. Mid_Hyph Equ    1EH            ;W* soft hyphen NOT at end of line
  131. Minspace equ    3            ;minimum # sequential spaces
  132.                     ; before a tab (adjust to your
  133.                     ; liking or circumstances).
  134.                     ;(No, I DON'T know what'll happen
  135.                     ; if you make it 0.)
  136.  
  137. Tabcnt  Dw    0            ;tab counter
  138. Rec    Db    Maxrec Dup (0)        ;Current record
  139. Sw    Db    0            ;Number of blanks skipped
  140. Qsw    Db    0            ;Quote switch
  141. Tabflg  db    0            ;non-zero for tabbing function
  142. Unsoft  db    0            ;Non-zero for W* Unsoft
  143. Lf_flag db    0            ;Lf counter for ensoft
  144. space_flag db    0            ;space counter for ensoft
  145. start_line db    0            ;new line flag for ensoft
  146.  
  147. Stk_Top Dw    0            ;SP at entry
  148.  
  149. MsgIn    Db    Cr,Lf,'Enter INPUT file name-  ',255
  150. Msg1    Db    Cr,Lf,'Input failed to open, '
  151. InKey    Db    32,32            ;Keyboard buffer
  152. Input    Db    76 Dup (0),0,255    ;Drive:path\name.ext
  153. IHandle Dw    0            ;Input file handle
  154. Ilen    Dw    0            ;Input block length
  155. Iptr    Dw    0            ;Offset to next char
  156. In_Ptr  Dw    0            ;Seg offset
  157.  
  158. MsgOut  Db    Cr,Lf,'Enter OUTPUT file name- ',255
  159. Msg2    Db    Cr,Lf,'Output failed to open, '
  160. OutKey  Db    32,32
  161. Output  Db    76 Dup (0),0,255
  162. OHandle Dw    0            ;Output file handle
  163. Olen    Dw    0            ;Bytes in output buffer
  164. Optr    Dw    0            ;Offset to next char
  165. Out_Ptr Dw    0            ;Seg offset
  166.  
  167. DTA    Db    48 Dup (0)
  168.     Page
  169. Sorry    Db    Cr,Lf,'Sorry, DOS Version 2 required',Cr,Lf,255
  170. Msg3f    Db    Cr,Lf,'I/O error reading',Cr,Lf,255
  171. Msg40    Db    Cr,Lf,'I/O error writing',Cr,Lf,255
  172. Msg4a    Db    Cr,Lf,'Insufficient memory',Cr,Lf,255
  173. Msg4e    Db    Cr,Lf,'No matching file(s) found',Cr,Lf,255
  174. InformD Db      'De-'
  175. Cooking Db      'Tabbing, ',255
  176. SoftStr db      'nsofting:   ',255
  177. Mark    Db      ' => ',255
  178. EofMsg  Db    Cr,Lf,'End of File',Cr,Lf,255
  179.  
  180. Code2    Db      'File not found ',255
  181. Code3    Db      'Path not found ',255
  182. Code4    Db      'Too many files ',255
  183. Code5    Db      'Access denied  ',255
  184. CmdLine db 'TOADSOFT Version 1.1, Toad Hall, 15 Jan 86, public domain',cr,lf
  185.  db 'Command:',cr,lf
  186.  db 'TOADSOFT [d:][\p\][ source.typ][ target.typ] [/t][/u][/tu]',cr,lf
  187.  db 'where source is file to be changed,',cr,lf
  188.  db '      target is destination file (names MUST be different)',cr,lf
  189.  db 'and options t = tabify (change spaces to tabs),',cr,lf
  190.  db '            u = unsoften (change W* file to ASCII).',cr,lf
  191.  db 'Defaults are Ensoften and expand tabs to spaces.',cr,lf,255
  192.  
  193. ;
  194. ;    Replace blanks with tabs
  195.  
  196. GenTab  Proc    Near
  197.  
  198. Loop:    Call    GetRec            ;Get a record, length in CX
  199.     Sub    BX,BX            ;Output column
  200.     Mov    Sw,BL            ;No blanks yet
  201.     Mov    Qsw,BL            ;No quotes yet
  202.     Or    CX,CX            ;Any data in record?
  203.     jnz    Set1            ;yep
  204.     jmp    Null            ; no, just CR-LF
  205.  
  206. ;stuffed this in here cause the jumps were getting too long...
  207.  
  208. Done:    cmp    Lf_flag,0        ;still owe a cr/lf?
  209.     jz    Done1            ; nope
  210.     call    DoHarCrLf        ;save a cr/lf
  211. Done1:    mov    AL,Eof
  212.     jmp    PutChar            ;save that CtrlZ and return
  213.  
  214.  
  215. Set1:    Mov    SI,Offset Rec        ;Look for blanks and
  216. Wloop:  Lodsb                ; replace strings of blanks
  217.     Cmp    AL,EOF            ;End of file?
  218.     Je    Done            ; yes, all done
  219.     Inc    BX            ; with tab characters
  220.     cmp    Tabflg,255        ;are we tabifying?  If not, we don't
  221.                     ; have any spaces saved anyway.
  222.     jne    Copy            ; nope, just save the char
  223.  
  224. ; Don't count blanks within single or double quoted strings
  225.     Cmp    AL,D_Quote        ;Double quote?
  226.     Jne    Chk1            ; nope, go check single
  227.     Xor    Qsw,2            ; turn on/off the 2-bit for "
  228.     Jmp    Chk2
  229.  
  230. Chk1:    Cmp    AL,S_Quote        ;single quote?
  231.     jne    Chk2            ; nope
  232.     cmp    Rec[SI+1],'t'        ;a n't?
  233.     je    Copy            ; yep, just skip it
  234.     Xor    Qsw,1            ; turn on/off the 1-bit for '
  235.  
  236. Chk2:    test    Qsw,3            ;within quotes?
  237.     Jnz    Insert            ; yep, save them
  238. ;--- done with quotations
  239.  
  240. ;our column counter is in BL.
  241. Chk3:    cmp    BL,08H            ;no tabs till col 9
  242.     jle    Insert            ;...and Insert'll take care of any
  243.                     ;   leading spaces
  244.     mov    AH,BL            ;(not using AH for anything)
  245. ;this gets weird, but it's Boolean... and it works...
  246.  
  247.     dec    AH            ; (don't ask...)
  248.     test    AH,07H            ;ready for a tab?
  249.     jnz    Insert            ; nope, see if we must insert
  250.                     ;  skipped spaces.
  251.  
  252. ;we have a character, and we're on a tab column.
  253. ;we'll only tab if we have Minspace spaces before this char.
  254.  
  255. Check:  cmp    Sw,Minspace        ;minimum space?
  256.     jl    Insert            ; not enough spaces, gotta insert
  257.     call    Test_Count